<?php
/**
 * User: @lixu
 * Date: 2019-04-10
 * Time: 15:43
 */

ini_set('display_errors', 1); // 配置文件设置了错误不可见， 使用ini_set命令设置可见
error_reporting(-1); // 设置php错误级别 -1 为显示所有级别的错误
require_once '/data/wwwroot/g_vendor/autoload.php'; // 引入自动加载，因为项目的自动加载是在vendor里面

use Biz\model\GoodsBasicInfo as mGoodsBasicInfo;
use Biz\model\GoodsStockLog as mGoodsStockLog;

// 将所有的不为0的数据都修改为0， 之后每次跑十万条数据。
$result = mGoodsBasicInfo::updateByWhere(['sell_total' => '0'], ['sell_total[!]' => '0']);

die;

$result = mGoodsStockLog::select(['change_num', 'goods_id'], [
    'AND' => [
        'type[!]' => mGoodsStockLog::TYPE_ADMIN_ACTION
    ],
    'LIMIT' => [0, 100000]
]);

$goodsInfo = [];
foreach ($result as $value) {
    $value['change_num'] = abs($value['change_num']);
    if(!isset($goodsInfo[$value['goods_id']])) {
        $goodsInfo[$value['goods_id']]['change_num'] = $value['change_num'];
    } else {
        $goodsInfo[$value['goods_id']]['change_num'] = $goodsInfo[$value['goods_id']]['change_num'] + $value['change_num'];
    }
}


foreach ($goodsInfo as $goodsId => $value) {
    $result = mGoodsBasicInfo::updateByWhere(['sell_total[+]' => $value], ['goods_id' => $goodsId]);
    var_dump($result);
}
die;
//$goodsList = mGoodsBasicInfo::select('*', ['first_online_time' => '0000-00-00 00:00:00']);

$result1 = mGoodsBasicInfo::updateByWhere(['first_online_time' => '1970-01-02 08:00:00'], ['first_online_time' => '0000-00-00 00:00:00']);
$result2 = mGoodsBasicInfo::updateByWhere(['operate_time' => '1970-01-02 08:00:00'], ['operate_time' => '0000-00-00 00:00:00']);

var_dump($result1,$result2);die;
